
<div class='weui-flex' id="user-address-modify" style="min-height:400px;width:80%;margin: 0 auto;"
     xmlns="http://www.w3.org/1999/html">
    <div class='weui-flex__item' style='flex:1.5; '>
        <div class="bc-list"  id="address_list" data-port="http://api.hongyanche.com/mall/address_list" data-id="address_id">
            <div class='weui-cells__title'>收货地址列表</div>
            <div class="bc-list-template" >
                <div class="weui-cells" style="background-color: rgba(245,245,245,0.7);border-radius:5px 5px 0 0;line-height: 25px;">
                    <div style="font-size: 20px">
                    &nbsp;&nbsp;<address_name list=1></address_name>
                    &nbsp;&nbsp;<address_tel  list=1></address_tel>
                    &nbsp;&nbsp;<landline list=1></landline>
                    <div>
                        <!--&nbsp; <address_province list=1></address_province>&nbsp;&nbsp;<address_city list=1></address_city>&nbsp;&nbsp;<address_district list=1></address_district>&nbsp;&nbsp;<address list=1 style="display: inline"></address>-->
                        &nbsp;&nbsp;<addressfull list=1></addressfull>
                    </div>
                        <div style="float: right;padding-right: 30px;">
                            &nbsp;<address_id class="hidden" id="address_id" list=1></address_id>
                            <a class="weui-btn weui-btn_fle1x weui-btn_primary address-remove">删除</a>&nbsp;&nbsp;&nbsp;<default list=1 class="hidden"></default><a class="weui-btn weui-btn_fle1x weui-btn_primary address-default">设为默认值</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class='weui-flex__item'>
        <div class='weui-cells__title'>收货地址编辑</div>
        <div class='weui-cells bc-district'>
            <div class='weui-cell'>
                <div class='weui-cell__hd'>
                    <label class='weui-label'>姓名</label>
                </div>
                <div class='weui-cell__bd'>
                    <input id="name-modify" class='user-address-modify weui-input' info=1 name='address_name' placeholder="请输入姓名" />
                </div>
            </div>
            <div class='weui-cell'>
                <div class='weui-cell__hd'>
                    <label class='weui-label'>电话</label>
                </div>
                <div class='weui-cell__bd'>
                    <input class='user-address-modify weui-input' info=1 name='address_tel' placeholder="请输入电话号码" />
                </div>
            </div>
            <div class='weui-cell'>
                <div class='weui-cell__hd'>
                    <label class='weui-label'>座机</label>
                </div>
                <div class='weui-cell__bd'>
                    <input class='user-address-modify weui-input' info=1 name='landline' placeholder="例:023-12345678" />
                </div>
            </div>
            <div class='weui-cell'>
                <div class='weui-cell__hd'>
                    <label class='weui-label'>省市</label>
                </div>
                <div class='weui-cell__bd'>
                    <!-- <input class='user-modify weui-input' info=1 name='province' placeholder="请输入所在省市" /> -->
                    <select class='user-address-modify weui-input' id='a'  in1fo=1 name='province' placeholder="请输入所在省市" ></select>
                </div>
            </div>
            <div class='weui-cell'>
                <div class='weui-cell__hd'>
                    <label class='weui-label'>市区</label>
                </div>
                <div class='weui-cell__bd'>
                    <select class='user-address-modify weui-input' id="b"  info=1 name='city' placeholder="请输入所在市区" ></select>
                    <!-- <input class='user-modify weui-input' info=1 name='city' placeholder="请输入所在市区" /> -->
                </div>
                <div class='weui-cell__hd'>
                    <label class='weui-label'>区县</label>
                </div>
                <div class='weui-cell__bd'>
                    <!-- <input class='user-modify weui-input' info=1 name='district' placeholder="请输入所在区县" /> -->
                    <select class='user-address-modify weui-input' id ="c" info=1 name='district' placeholder="请输入所在区县" ></select>
                </div>
            </div>
            <div class='weui-cell'>
                <div class='weui-cell__hd'>
                    <label class='weui-label'>详细地址</label>
                </div>
                <div class='weui-cell__bd'>
                    <input class='user-address-modify weui-input' info=1 name='address' placeholder="请输入详细地址" />
                </div>
            </div>
            <div class='weui-cell'>
                <div class='weui-cell__hd'>
                    <label class='weui-label'>邮编</label>
                </div>
                <div class='weui-cell__bd'>
                    <input class='user-address-modify weui-input' info=1 name='address_code' placeholder="请输入邮编" />
                </div>
            </div>
            <!--<div class='weui-cell'>-->
                <!--<div class='weui-cell__hd'>-->
                    <!--<label class='weui-label'>其他</label>-->
                <!--</div>-->
                <!--<div class='weui-cell__bd'>-->
                    <!--<input class='user-address-modify weui-input' info=1 name='other' placeholder="请输入其他" />-->
                <!--</div>-->
            <!--</div>-->
        </div>
        <div class='weui-btn-area'>
            <a id='address-add-confirm' href="javascript:;" class="weui-btn weui-btn_fle1x weui-btn_primary">添加</a>
        </div>
    </div>






</div>
<style>
    .weui-loadmore {
         width: 100%;
        margin: 1.5em auto;
        line-height: 1.6em;
        font-size: 14px;
        text-align: center;
    }
    .address-remove{
        display: inline;
        padding: 5px 6px 5px 6px;
        font-size: 16px;
        background-color: rgba(255,0,0,0.7);
    }
    .address-default{
        display: inline;
        padding: 5px 6px 5px 6px;
        font-size: 16px;
    }
    .default-button{
        font-size: 16px;
        border: 1px solid rgba(0,0,0,0.2);
        width: 200%;
        height: 200%;
        padding: 5px 6px 5px 6px;
        background-color: #eee;
        border-radius: 5px;
    }
</style>
<script>
    $(function () {
        $('#address_list').on('bc-list-success',function () {
            $(this).find('default').each(function(index, el) {
                console.log($(el).text())
                if($(el).text()==1){
                    $(el).next('a').removeClass()
                    $(el).next('a').addClass('default-button')
                }
            });
            $(this).find('.weui-cells')[0].style.background='rgb(240,255,255)';
        })
    });
    POST.init('#address-add-confirm',{
        text:"添加",
        url:'/mall/address_create',
        input:function(){
            var r = {};
            $('.user-address-modify').each(function(index, el) {
                r[$(el).attr('name')] = $(el).val();
            });
		return r;
        },
        success:function(){
            $('.user-address-modify').each(function(index, el) {
                 $(el).val('');
                 LIST.reload('#address_list');
            });
        }
    });
    $('#user-address-modify').on('click','.address-remove',function(){
        var address_id = $(this).prev('#address_id').text()
        if(confirm("确定删除该地址吗？")) {
            $.ajax({
                type: "post",
                url: '/mall/address_remove',
                data: {address_id: address_id},
                success: function (ret) {
                    $('.user-address-modify').each(function (index, el) {
                        LIST.reload('#address_list');
                    });
                },
            })
        }
    });
    $('#user-address-modify').on('click','.address-default',function(){
        var address_id = $(this).prev('default').prev('a').prev("#address_id").text()
        if(confirm("确定设为默认值吗？")) {
            $.ajax({
                type: "post",
                url: '/mall/address_default',
                data: {address_id: address_id},
                success: function (ret) {
                    $('.user-address-modify').each(function (index, el) {
                        LIST.reload('#address_list');
                    });
                },
            })
        }
    });
</script>